<?php
class ZdscbsController extends AppController {

	var $name = 'Zdscbs';
    var $uses=array('Zdscb','Chidoansv');
	function index() {
		//$this->Zdscb->recursive = 0;
		//$this->set('zdscbs', $this->paginate());
        $id = $this->Session->read('chidoanht_id');
		$zdscbs=$this->Zdscb->find('all',array('conditions'=>array('chidoansv_id'=>$id)));
        $this->set('zdscbs', $zdscbs);
	}
    function dscb() {
        $id = $this->Session->read('chidoanht_id');
        $this->layout = 'excel';
		$zdscbs=$this->Zdscb->find('all',array('conditions'=>array('chidoansv_id'=>$id)));
        $this->set('zdscbs', $zdscbs);
	}
    function dscdcb(){
        $cds=$this->Chidoansv->find('all',array('conditions'=>array('Chidoansv.khoahoc_id'=>null)));
        $this->set('cds', $cds);
    }
    function multiexp(){
        if(!empty($this->data)){
            //pr($this->data);exit;
            $cdids = array();              
    		foreach($this->data['Zdscb']['cdid'] as $id => $value){
    			if($value == 1){
    	  		  $cdids[] = $id;
    			}
    		}
            //$zdscbs=$this->Zdscb->find('all',array('conditions'=>array('or'=>array('Zdscb.chidoansv_id'=>$cdids)),'recursive'=>-1));
            $results=array();
            foreach ($cdids as $cdid){
                $results[$cdid]=$this->Zdscb->find('all',array('conditions'=>array('Zdscb.chidoansv_id'=>$cdid),'recursive'=>-1));
            }
            $this->set('cdids',$cdids);
            $this->set('results',$results);
            $this->layout = 'excel';
        }
        
    }
	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid zdscb', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('zdscb', $this->Zdscb->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Zdscb->create();
			if ($this->Zdscb->save($this->data)) {
				$this->Session->setFlash(__('The zdscb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The zdscb could not be saved. Please, try again.', true));
			}
		}
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid zdscb', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Zdscb->save($this->data)) {
				$this->Session->setFlash(__('The zdscb has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The zdscb could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Zdscb->read(null, $id);
		}
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for zdscb', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Zdscb->delete($id)) {
			$this->Session->setFlash(__('Zdscb deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Zdscb was not deleted', true));
		$this->redirect(array('action' => 'index'));
	}
}
